﻿using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using lwd800.Views.Pages;

namespace lwd800.ViewModels
{
    public class ProductionPageViewModel : INotifyPropertyChanged
    {
        private int _selectedFirstMenuIndex;

        public int SelectedFirstMenuIndex
        {
            get => _selectedFirstMenuIndex;
            set
            {
                if (_selectedFirstMenuIndex != value)
                {
                    _selectedFirstMenuIndex = value;
                    OnPropertyChanged();
                    // 一级菜单切换时，二级菜单恢复为第一个
                    SelectedSubMenuIndex = 0;
                    // 可选：切换一级菜单时也可以切换页面
                }
            }
        }

        private int _selectedSubMenuIndex;

        public int SelectedSubMenuIndex
        {
            get => _selectedSubMenuIndex;
            set
            {
                if (_selectedSubMenuIndex != value)
                {
                    _selectedSubMenuIndex = value;
                    OnPropertyChanged();
                }
            }
        }
        private object _currentSubPage;
        public object CurrentSubPage
        {
            get => _currentSubPage;
            set
            {
                _currentSubPage = value;
                OnPropertyChanged();
            }
        }

        public ICommand SelectFirstMenuCommand { get; }
        public ICommand SelectSecondMenuCommand { get; }
        public ICommand SelectThirdMenuCommand { get; }
        public ICommand SelectSubMenu1Command { get; }
        public ICommand SelectSubMenu2Command { get; }
        public ICommand SelectSubMenu3Command { get; }
        public ICommand SelectSubMenu4Command { get; }
        public ICommand SelectSubMenu5Command { get; }

        public ProductionPageViewModel()
        {
            SelectFirstMenuCommand = new RelayCommand(_ => SelectedFirstMenuIndex = 0);
            SelectSecondMenuCommand = new RelayCommand(_ => SelectedFirstMenuIndex = 1);
            SelectThirdMenuCommand = new RelayCommand(_ => SelectedFirstMenuIndex = 2);

            SelectSubMenu1Command = new RelayCommand(_ =>
            {
                SelectedSubMenuIndex = 0;
                CurrentSubPage = new RGVRoundOnePage(); //切换页面
            });
            SelectSubMenu2Command = new RelayCommand(_ =>
            {
                SelectedSubMenuIndex = 1;
                // CurrentSubPage = new SomeOtherPage();
            });
            SelectSubMenu3Command = new RelayCommand(_ =>
            {
                SelectedSubMenuIndex = 2;
                // CurrentSubPage = new AnotherPage();
            });
            SelectSubMenu4Command = new RelayCommand(_ =>
            {
                SelectedSubMenuIndex = 3;
                // CurrentSubPage = new YetAnotherPage();
            });
            SelectSubMenu5Command = new RelayCommand(_ =>
            {
                SelectedSubMenuIndex = 4;
                // CurrentSubPage = new LastPage();
            });

            // 默认显示菜单1
            SelectedFirstMenuIndex = 0;
            SelectedSubMenuIndex = 0;
            CurrentSubPage = new RGVRoundOnePage();
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged([CallerMemberName] string name = null)
            => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
    }

   
}